#include <TM1638.h>
#include <TM1640.h>
#include <SPI.h>
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'+','0','-','A'},
  {'1','2','3','B'},
  {'4','5','6','C'},
  {'7','8','9','D'}
};
byte rowPins[ROWS] = {6, 5, 4, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {10, 9, 8, 7}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

// define a module on data pin 8, clock pin 9 and strobe pin 7
TM1638 module(12, 13, 11);

byte dots = 1;
//long value = 0x1234ABCD;
long value = 0x1234ABCD;

void setup() {
 // initialize serial communication at 9600 bits per second:
 Serial.begin(9600);
 // initialize Ethernet Shield
 //Ethernet.begin(mac, ip);
 // display a hexadecimal number and set the left 4 dots
 module.setDisplayToHexNumber(value, 0xF0);
 //module.clearDisplay();
}

void loop() {
  char customKey = customKeypad.getKey();
  
  if (customKey){
    Serial.println(customKey);
  }
  
  module.setDisplayToString(String(customKey),dots,true);
  //module.setDisplayToDecNumber(value, dots, true);

 // light the first 4 red LEDs and the last 4 green LEDs as the buttons are pressed
 //module.setLEDs(((keys & 0xF0) << 8) | (keys & 0xF));

 dots = (dots * 2);
 if (dots == 0) {
 dots = 1;
 }
}

